Ext.ns('SM.Explanation.ExplanationManage')

SM.Explanation.ExplanationManage=Ext.extend(Ext.grid.GridPanel,{});
/**
 * 查看详细信息
 * @param {} t
 */
SM.Explanation.ExplanationManage.show=function(t) {
	//如果为button
	var grid;
	if (t instanceof Ext.Button) {
		grid =t.ownerCt.ownerCt
	} else {
		grid =t;
	}
	var recs =grid.getSelectionModel().getSelections()
	if (recs.length==0) {
		return;
	}
	 Ext.Ajax.request({
            params:{'tpSmExplanation.explanationId':recs[0].get('explanationId')}
            ,method:'post'
            ,url:'explanation_get.action'
            ,success:function(result,request){
                	var page =Ext.decode(result.responseText);
                	if (page.status ==200){
                		var tpSmExplanation =page.data;
                		new SM.Explanation.Show({
                	       title:tpSmExplanation.explanationName
                	       ,content:tpSmExplanation.explanationContent
                		}).show();
                	}
                }
	});
}
/**
 * 新增
 * @param {} t
 */
SM.Explanation.ExplanationManage.add =function(t){
	new SM.Explanation.Edit({title:'说明新增'
	                         ,store:t.ownerCt.ownerCt.store}).show()
}


/**
 * 搜索页面
 * @class SM.Explanation.ExplanationManage.search
 * @extends Ext.Window
 */
SM.Explanation.ExplanationManage.search =Ext.extend(Ext.Window,{
     title:'按条件查询'
     ,modal:true
     ,width:'500'
     ,closeAction:'hide'
     ,initComponent:function(){
     	this.items =[{xtype:'form'
     				,labelAlign:'right'
     				,buttonAlign:'center'
     	            ,frame:true
     	            ,padding:10
     	            ,buttons:[ {text:'确定'
     	            			,handler:function(){
     	            	              var form =this.ownerCt.ownerCt.form;
     	            	              var valid =true;
     	            	              var params={};
     	            	              form.items.each(function(n){
     	            	                     if(!n.isValid()) {
     	            	                     	Ext.Msg.alert('提示',n.fieldLabel+n.getActiveError());
     	            	                     	valid =false;
     	            	                     	return false;
     	            	                     }
     	            	                     if (n.getValue()!="") {
     	            	                     	params['tpSmExplanation.'+n.name] =n.getValue();
     	            	                     }
     	            	              });
     	            	              if (!valid) {
     	            	              	return;
     	            	              }
     	            	              var grid =this.ownerCt.ownerCt.ownerCt.grid;
     	            	              grid.store.baseParams=params 
     	            	              grid.store.load({
     	            	                  start:0
     	            	                  ,limit:grid.limit
     	            	              });
     	            	              this.ownerCt.ownerCt.ownerCt.hide();
     	            			}
     	            		},{
								text : '重置',
								handler : function() {
									this.ownerCt.ownerCt.form.reset();
								}
							}, {
								text : '取消',
								handler : function() {
									this.ownerCt.ownerCt.ownerCt.hide();
								}
							} ]
     				,items:[{xtype:'numberfield'
			     	        ,fieldLabel:'说明标识'
			     	        ,width:'300'
			     	        ,name:'explanationId'
			     	        ,maxLength:8}
			     	       ,{xtype:'textfield'
			     	        ,fieldLabel:'说明名称'
			     	        ,width:'300'
			     	        ,name:'explanationName'
			     	        ,maxLength:50}
			     	       ,{xtype:'textfield'
			     	        ,fieldLabel:'说明摘要'
			     	        ,width:'300'
			     	        ,name:'explanationRemark'
			     	        ,maxLength:50}]
			     	   }
     	       
     	];
     	SM.Explanation.ExplanationManage.search.superclass.initComponent.call(this);
     }
});

/**
 * 说明表格操作按钮
 * @type 
 */
SM.Explanation.ExplanationManage.buildBbar =function(){
           return [ {
           				text:'按条件查询'
           				,iconCls: 'ico-dot-search'
           				,handler:function(){
           					 var grid =this.ownerCt.ownerCt;
           					 if (!grid.search) {
           					 	grid.search =new SM.Explanation.ExplanationManage.search(
           				     			{grid:this.ownerCt.ownerCt}
           				        );
           					 }
           				      grid.search.show();
           				}
                    }
                    ,'-'
                    ,{
                   		 text:'查看'
                   		 ,iconCls:'ico-task-show'
                   		 ,handler:SM.Explanation.ExplanationManage.show
                    }
                    ,'-'
                    ,{
                   		 text:'新增'
                   		 ,iconCls:'ico-task-add'
                   		 ,handler:SM.Explanation.ExplanationManage.add
                    }
                    ,'-'
                    ,{
                    	text:'编辑'
                    	,iconCls:'ico-task-edit'
                    	,handler:SM.Explanation.update
                    }
                    ,'-'
                    ,{
                    	text:'操作说明'
                    	,iconCls:'ico-dot-question'
                    	,handler:function(){
                    		SM.Explanation.showExplanation(9);
                    	}
                    }
                   ]
         }
//加载配置文件
Ext.apply(SM.Explanation.ExplanationManage.prototype,{
	 closable: true
	 ,columnLines:true
	 ,loadMask:{msg:'请稍候，正在加载中。。。'}
   	 ,autoScroll:true
	 ,viewConfig:{
	 	forceFit :true
	 	,headerAlign:'center'
	 }
	 ,listeners:{
	 	rowdblclick:SM.Explanation.ExplanationManage.show
	 	,destory:function(){
	 	    if (this.search) {
	 	    	this.search.destory();
	 	    }
	 	}
	 }
	 ,tbar:SM.Explanation.ExplanationManage.buildBbar()
     ,initComponent:function(){
     	var limit =100;
     	this.limit =limit;
     	var emstore =new Ext.data.JsonStore({
     	     url:'explanation_getByPage.action'
     	     ,fields:['explanationId','explanationName','explanationRemark','flag']
     	     ,root:'root'
     	     ,totalProperty:'totalProperty'
     	});
     	emstore.limit =limit;
     	var sm =new Ext.grid.CheckboxSelectionModel({
					dataIndex: "explanationId",
	                sortable: false,
	                singleSelect:false,
	                width:20
				});
				
     	this.store =emstore;
     	this.sm =sm;
     	this.columns =[sm
     	               ,{
				        header:'说明标识',
						sortable:true
						,dataIndex:"explanationId"
						,width:30
					   },{
				        header:'说明名称',
						sortable:true
						,dataIndex:"explanationName"
					   },{
				        header:'说明摘要',
						sortable:true
						,dataIndex:"explanationRemark"
						,width:250
					   }]
		 this.bbar=new Ext.PagingToolbar({
				pageSize : limit,
				store : emstore,
				displayInfo : true,
				displayMsg : '第 {0} - {1} 条  共 {2} 条',
				emptyMsg : "没有记录"
			})		   
		emstore.load({params:{limit:limit,start:0}});			   
     	SM.Explanation.ExplanationManage.superclass.initComponent.call(this);
     }
});


